/**
 * 
 */
package com.jjt.kiki.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;

import com.jjt.kiki.bean.Done;
import com.jjt.kiki.bean.No;

/**
 * @author jjtEatJava
 *
 */
public class DoneDao extends BaseDao{
	/**
	 * jjtEatJava
	 * 2017年5月9日
	 * @param uk
	 * @return
	 */
	public int countByNoUserUk(String uk) {
		Connection conn = null;
		PreparedStatement statement =null;
		try {
			conn = this.getConnection();
			statement = conn.prepareStatement("select count(*) from tb_done where done_user_uk = ?");
			statement.setString(1,uk);
			ResultSet set = statement.executeQuery();
			set.next();
			int count = set.getInt(1);
			statement.close();
			conn.close();
			return count;
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				statement.close();
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return -1;
	}

	/**
	 * jjtEatJava
	 * 2017年5月9日
	 * @param no
	 */
	public void save(Done done) {
		Connection conn = null;
		PreparedStatement statement =null;
		try {
			conn = this.getConnection();
			statement = conn.prepareStatement("insert into tb_done (done_id,done_user_uk,fans_count,follow_count,pubshare_count,album_count) values(?,?,?,?,?,?)");
			statement.setString(1,UUID.randomUUID().toString());
			statement.setString(2,done.getDoneUserUk());
			statement.setInt(3,done.getFansCount());
			statement.setInt(4,done.getFollowCount());
			statement.setInt(5,done.getPubshareCount());
			statement.setInt(6,done.getAlumCount());
			
			statement.execute();
			statement.close();
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				statement.close();
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}
